/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package app;

import java.awt.Color;
import java.awt.Component;
import javax.swing.BorderFactory;
import javax.swing.JTable;
import javax.swing.border.Border;
import javax.swing.table.DefaultTableCellRenderer;

/**
 *
 * @author yoshi
 */
public class MyCellRenderer extends DefaultTableCellRenderer {
    // copy from Mac widgets

    protected static final Color EVEN_ROW_COLOR = new Color(241, 245, 250);
    protected static final Color TABLE_GRID_COLOR = new Color(0xd9d9d9);
    protected static final Color SELECTION_ACTIVE_SELECTION_FOREGROUND_COLOR = Color.WHITE;
    protected static final Color SELECTION_ACTIVE_SELECTION_BACKGROUND_COLOR = new Color(0x3d80df);
    protected static final Color SELECTION_INACTIVE_SELECTION_FOREGROUND_COLOR = Color.BLACK;
    protected static final Color SELECTION_INACTIVE_SELECTION_BACKGROUND_COLOR = new Color(0xc0c0c0);
    protected static final Color SELECTION_ACTIVE_BOTTOM_BORDER_COLOR = new Color(125, 170, 234);
    protected static final Color SELECTION_INACTIVE_BOTTOM_BORDER_COLOR = new Color(224, 224, 224);
    protected static final Color TRANSPARENT_COLOR = new Color(0, 0, 0, 0);
    private int align;
    private Border selectedBorder = BorderFactory.createMatteBorder(0, 1, 0, 1, SELECTION_ACTIVE_BOTTOM_BORDER_COLOR);
    private Border inselectedBorder = BorderFactory.createMatteBorder(0, 1, 0, 1, SELECTION_INACTIVE_BOTTOM_BORDER_COLOR);

    public MyCellRenderer(int align) {
        this.align = align;
    }

    @Override
    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
        Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
        
        if (((MyTable) table).getItuneColumns().contains(column)) {
            if (table.getSelectedRow() == row) {
                this.setBackground(SELECTION_ACTIVE_SELECTION_BACKGROUND_COLOR);
                this.setForeground(SELECTION_ACTIVE_SELECTION_FOREGROUND_COLOR);
                this.setBorder(selectedBorder);
            } else {
                if (row % 2 == 0) {
                    this.setBackground(EVEN_ROW_COLOR);
                } else {
                    this.setBackground(Color.WHITE);
                }
                this.setForeground(SELECTION_INACTIVE_SELECTION_FOREGROUND_COLOR);
                this.setBorder(inselectedBorder);
            }
        }

        this.setHorizontalAlignment(align);

        return c;
    }
}
